﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace SMS.BaseClass
{
    class Utils
    {
        /// <summary>
        /// 将对象转换为字符串
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public string ObjToString(Object obj)
        {
            string str = string.Empty;

            if (obj != null)
            {
                str = obj.ToString();
            }

            return str;

        }

        public string GetCode(String strCodeType)
        {
            SMS.BaseClass.DataCon datacon = new SMS.BaseClass.DataCon();
            // 最大Code+1
            string strSQL = "UPDATE T_CODE SET CODE_MAX = CODE_MAX + 1 WHERE CODE_TYPE = '" + strCodeType + "';";
            datacon.getcom(strSQL);

            // 取得最新Code
            strSQL = "SELECT PREFIX + RIGHT('0000000000000000000000000000000000000000'+CAST(ISNULL(CODE_MAX,0) AS VARCHAR),CODE_LENGTH) AS CODE_MAX" + 
                    " FROM T_CODE WHERE CODE_TYPE = '" + strCodeType + "';";
            string strCodeMax = this.ObjToString(datacon.getds(strSQL, "T_CODE").Tables["T_CODE"].Rows[0]["CODE_MAX"].ToString());

            return strCodeMax;
        }
    }
}
